#!/usr/bin/env python
# -*- coding: utf-8 -*-
###################################################################
# Copyright(c) Genecast, all rights reserved
# @file        : n_door_zxc.py
# @author      : zhang.xiancang
# @mail        : zhang.xiancang@genecast.com.cn
# @revision    : Tue Nov  8 09:33:38 2022
# @description : 
###################################################################
import random
import pdb
import argparse


def my_parser ():
    parser = argparse.ArgumentParser(description="n-door 游戏概率")
    parser.add_argument('-n', '--door_n', help = "共有n扇门",required = True)
    parser.add_argument('-t' ,'--test_n', help = "模拟抽奖c次",required = True)
    argv = parser.parse_args()
    return argv


class n_door_zxc:
    def __init__(self,argv,change_door):
        self.n = argv.door_n
        self.change_door = change_door
    def paly_games(self):
        # 选取门的编号为 a
        a = random.randint(1,int(self.n))
        # 有财宝门的编号为 b
        b = random.randint(1,int(self.n))
        # 不换门
        if self.change_door == 1:
            if a == b:
                return 0
        # 换门
        else:
            if a == b:
                return 1
            else:
                return 0

if __name__ == "__main__":
    argv = my_parser()
    # 尝试抽奖的次数为test_n
    test_n = argv.test_n
    door_n = argv.door_n
    # 获得财宝的次数
    number_1_x = 0
    # 失败的次数
    number_1_y = 0
    # 是否换门，0为换门，1为不换门
    # 不换门的概率计算
    change_door = 1
    door_games_project = n_door_zxc(argv,change_door)
    for change_1 in range(1,int(test_n)+1):
        if door_games_project.paly_games() == 0:
            number_1_x +=1
        else:
            number_1_y +=1
    values_door = float(number_1_x/int(test_n))
    all_1_number = int(number_1_x) + int(number_1_y)
    print(f"门的数量为{door_n}")
    print(f"不换门获得财宝的概率为{values_door}")
    print(f"不换门抽奖的次数为{all_1_number}")
    # pdb.set_trace()

    # 换门的概率计算
    number_0_x = 0
    number_0_y = 0
    change_door = 0
    door_games_project = n_door_zxc(argv,change_door)
    for change_0 in range(1,int(test_n)+1):
        if door_games_project.paly_games() == 0:
            number_0_x +=1
        else:
            number_0_y +=1
    values_door = float(number_0_x/int(test_n))
    all_0_number = int(number_0_x) + int(number_0_y)
    print(f"换门获得财宝的概率为{values_door}")
    print(f"换门抽奖的次数为{all_0_number}")


